package com.yellowpage.ca.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.ca.data.Dictionary;
import com.yellowpage.ca.dao.DictionaryDao;

public class DictionaryServiceImpl extends BaseServiceImpl implements
		DictionaryService {
	private DictionaryDao dictionaryDao;

	public void setDictionaryDao(DictionaryDao dictionaryDao) {
		this.dictionaryDao = dictionaryDao;
	}

	/* Smooth generate Method */
	public Dictionary getDictionary(Long id) {
		return dictionaryDao.get(id);
	}

	public List<Dictionary> getAllDictionary() {
		return dictionaryDao.getAll();
	}

	@Override
	public List<Dictionary> getByDictType(String dictType) {
		return dictionaryDao.getByDictType(dictType);
	}

	@Override
	public Dictionary getByDictValueAndDictType(String dictValue,
			String dictType) {
		return dictionaryDao.getByDictValueAndDictType(dictValue, dictType);
	}

	@Override
	public Map<String, List<Dictionary>> getDictMap() {
		Map<String, List<Dictionary>> dictMap = new HashMap<String, List<Dictionary>>();
		List<String> dictTypeList = dictionaryDao.getDistinctDictTypes();
		for (String dictType : dictTypeList) {
			dictMap.put(dictType, new ArrayList<Dictionary>());
		}

		List<Dictionary> all = dictionaryDao.getAll();
		for (Dictionary dict : all) {
			dictMap.get(dict.getDictType()).add(dict);
		}

		return dictMap;
	}

}